package com.hexinfo.dmpro.dev.data.transfer.common.enums;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
public enum DevDataTransferRebuildListExceptionEnum {

    get_create_sql_exception("get_create_sql_exception", "获取建表语句异常:"),

    table_column_empty("table_column_empty", "该表查询到的字段信息为空"),

    not_supported_table("not_supported_table", "仅支持HIVE内部表和外部表数据同步");

    @Getter
    private final String name;

    @Getter
    private final String value;

    public static List<String> getValues() {
        return Arrays.stream(DevDataTransferRebuildListExceptionEnum.values()).map(DevDataTransferRebuildListExceptionEnum::getValue).collect(Collectors.toList());
    }

    public static DevDataTransferRebuildListExceptionEnum getByValue(String value) {
        return DevDataTransferRebuildListExceptionEnum.valueOf(value);
    }

    public static boolean isContains(String errorMessage) {
        for (DevDataTransferRebuildListExceptionEnum devDataTransferRebuildListExceptionEnum : DevDataTransferRebuildListExceptionEnum.values()) {
            if (StrUtil.isNotBlank(errorMessage) && errorMessage.contains(devDataTransferRebuildListExceptionEnum.getValue())) {
                return true;
            }
        }
        return false;
    }
}
